package com.useeinfo.oa.modules.maintaining.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.oa.common.utils.ResultUtil.ResultDto;
import com.useeinfo.oa.common.utils.ResultUtil.ResultUtil;
import com.useeinfo.oa.modules.base.enums.AuditTypeEnum;
import com.useeinfo.oa.modules.maintaining.dao.ApplyOrderDao;
import com.useeinfo.oa.modules.maintaining.dao.AuditOrderDao;
import com.useeinfo.oa.modules.maintaining.entity.ApplyOrder;
import com.useeinfo.oa.modules.maintaining.entity.AuditOrder;
import com.useeinfo.oa.modules.maintaining.entity.MaintainOrder;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AuditOrderBiz extends CrudBiz<AuditOrderDao, AuditOrder> {

    /**
     * 保存审批记录
     * @param maintainOrder
     * @param systemUser
     * @param pass
     * @param reason
     * @param auditTypeEnum
     * @param level
     * @return
     */
    public ResultDto saveOrUpdate(MaintainOrder maintainOrder, SystemUser systemUser, boolean pass, String reason, AuditTypeEnum auditTypeEnum,int level){
        AuditOrder auditOrder = new AuditOrder();
        auditOrder.setCreateDate(new Date());
        auditOrder.setAuditDate(new Date());
        auditOrder.setAuditTypeEnum(auditTypeEnum);
        auditOrder.setLevel(level);
        auditOrder.setAuditUser(systemUser);
        auditOrder.setPass(pass);
        auditOrder.setEnterprise(maintainOrder.getEnterprise());
        auditOrder.setReason(reason);
        auditOrder.setMaintainOrder(maintainOrder);
        if(!pass){
            auditOrder.setEffective(false);
        }
        dao.add(auditOrder);
        return ResultUtil.success();
    }
}
